﻿using CommunityToolkit.Mvvm.ComponentModel;
using Newtonsoft.Json;
using SSHTool.Util;
using System.Collections.ObjectModel;
using System.Linq;

namespace SSHTool.ViewModel
{
    public class FileViewModel : ObservableObject
    {
        private int _id;
        private int _type;
        private string _path;
        private string _name;
        private string _fileName;

        private ObservableCollection<VariableViewModel> _variableList;

        public int Id { get => _id; set => SetProperty(ref _id, value); }
        public int Type { get => _type; set => SetProperty(ref _type, value); }
        public string Path { get => _path; set => SetProperty(ref _path, value); }
        public string Name { get => _name; set => SetProperty(ref _name, value); }
        public string FileName { get => _fileName; set => SetProperty(ref _fileName, value); }

        public ObservableCollection<VariableViewModel> VariableList { get => _variableList; set => SetProperty(ref _variableList, value); }

        [JsonIgnore]
        public string VariableString
        {
            get
            {
                if (StringUtil.IsEmpty(VariableList))
                {
                    return string.Empty;
                }

                return string.Join("\r\n", VariableList.Select(m => $"[{m.Description}][{m.Key}]"));
            }
        }
    }
}
